﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.Model;
using IHISCETeim.Library;
using IHISCETeim.BLL;

namespace IHISCETeim.Web.MachineSys.MacModel
{
    public partial class OControlTicketAdd : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.新增 };
            }
        }

        protected override string DWZRef
        {
            get { return "OControlTicketList"; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (GetRequestValue<string>("ajaxmethod", "") == "add")
            {
                addmenu();
                
            }
        }

        protected void addmenu()
        {
            string[] ItemCodes = GetRequestValue<string>("ItemCode", "").Split(new char[] { ',' });
            string[] ItemNames = GetRequestValue<string>("ItemName", "").Split(new char[] { ',' });
            string[] Quantitys = GetRequestValue<string>("Quantity", "").Split(new char[] { ',' });
            string[] Notes = GetRequestValue<string>("Note", "").Split(new char[] { ',' });
          

            OControlTicketInfo obj = Request.SerializableObject<OControlTicketInfo>();
            List<OControlTicketItemInfo> ngitems = new List<OControlTicketItemInfo>();

            for (int index = 0; index < ItemCodes.Count(); index++)
            {
                OControlTicketItemInfo ngitem = new OControlTicketItemInfo();
                if (!string.IsNullOrEmpty(ItemCodes[index]))
                {
                    ngitem.ItemCode = ItemCodes[index];
                    ngitem.ItemName = ItemNames[index];
                    ngitem.TNO = obj.TNO;
                    ngitem.Quantity = Convert.ToInt32( Quantitys[index]);
                    ngitem.Note = Notes[index];
                    ngitems.Add(ngitem);
                }
            }
            this.AddLog(Permission.新增, null, obj);
            if (OControlTicketController.Add(obj, ngitems))
            {
                SuccessJson("新增成功", this.DWZRef);
            }
            else
            {
                ErrorJson("新增失败", this.DWZRef);
            }
        }

        public string GetControlReason(string controlname)
        {
            string[] ControlReasonArr = new string[] { "试制", "量试", "初量产", "国产化开发", "厂商变更", "设变管制", "新机型开发", "特别管制" };
            string checkboxtemp = "<input type=\"checkbox\" name=\"{0}\" value=\"{1}\" {2} />{1}";
            string returnHtml = "";
            foreach (string item in ControlReasonArr)
            {
                string c = "";
                returnHtml += string.Format(checkboxtemp, controlname, item, c);
            }
            return returnHtml;
        }
    }
}